import * as Router from 'koa-router';

const crypto = require('crypto');
const secp256k1 = require('secp256k1');
const keccak = require('keccak');

const router = new Router();
router.post('/newAccount', async (ctx: any) => {
  const privateKey = crypto.randomBytes(32);
  const publicKey = secp256k1.publicKeyCreate(privateKey, false).slice(1);
  const address = keccak('keccak256').update(publicKey).digest().slice(-20);
  ctx.body = {
    status: 200,
    data: '0x' + address.toString('hex')
  }
});

router.post('/deployTransaction', async (ctx: any) => {
  ctx.body = {
    status: 200,
    data: true,
  };
});

export default router;
